﻿// -------------------------------------------------------------------------
//    @FileName         :    NFWhiteListCache.h
//    @Author           :    gaoyi
//    @Date             :    24-8-15
//    @Email            :    445267987@qq.com
//    @Module           :    NFWhiteListCache
//
// -------------------------------------------------------------------------

#pragma once

#include <NFComm/NFShmStl/NFShmHashSet.h>

#include "proto_common_db.nanopb.h"
#include "NFComm/NFObjCommon/NFObject.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"

const int MAX_WHITE_LIST_NUM = 15000;

namespace std
{
    template<>
    struct hash<tbWriteList>
    {
        size_t operator()(const tbWriteList &data) const
        {
            return NFHash::hash_combine(data.account_id.ToString(), data.account_pwd.ToString());
        }
    };
}

bool operator==(const tbWriteList &lhs, const tbWriteList &rhs);

class NFWhiteListCache : public NF_OBJECT_GLOBAL_TEMPLATE_MACRO(NFWhiteListCache, EOT_LOGIC_WHITELIST_CACHE_ID, NFObject)
public:
    NFWhiteListCache();

    virtual ~NFWhiteListCache();

    int CreateInit();

    int ResumeInit();

public:
    int AddWhiteList(proto_ff::tbWriteList &oWhiteList);

    int DelWhiteList(proto_ff::tbWriteList &oWhiteList);

    bool IsInWhiteList(tbWriteList *pstWhiteList);

private:
    NFShmHashSet<tbWriteList, MAX_WHITE_LIST_NUM> m_oHashTable;
};
